#ifndef _HTTP_HEADER_HPP_
#define _HTTP_HEADER_HPP_

#include <crt_util.h>
#include <utilex/plus.hpp>

#define HTTP_ACCEPT                    "Accept"
#define HTTP_ACCEPT_CHARSET            "Accpet-Charset"
#define HTTP_ACCEPT_ENCODEING          "Accept-Encoding"
#define HTTP_ACCEPT_DATETIME           "Accept-Datatime"
#define HTTP_ACCEPT_LANGUAGE           "Accept-Language"
#define HTTP_AUTHORIZATION             "Authorization"
#define HTTP_CACHE_CONTROL             "Cache-Control"
#define HTTP_CONNECTION                "Connection"
#define HTTP_CONTEND_MD5               "Content-MD5"
#define HTTP_DATA                      "Data"
#define HTTP_EXPECT                    "Expect"
#define HTTP_FORWARDED                 "Forwarded"
#define HTTP_USE_AGENT                 "Use-Agent"
#define HTTP_KEEPALIVE                 "Keepalive"
#define HTTP_REFERER                   "Referer"
#define HTTP_RANGE                     "Range"
#define HTTP_UPGRADE_INSECURE_REQUESTS "Upgrade-Insecure-Requests"
#define HTTP_CONTENT_TYPE              "Content-Type"
#define HTTP_DNT                       "Dnt"
#define HTTP_COOKIE                    "Cookie"
#define HTTP_ETAG                      "ETag"
#define HTTP_HOST                      "Host"

#define HTTP_END "\r\n"

class http_header_t
{
public:
    http_header_t();
    virtual ~http_header_t();
    void reset();

    const char* build_res();
    void build_res_http();
    size_t build_res_len();
    const char* build_req();
    void build_req_http();
    size_t build_req_len();

    int add_cookie(const char* name, const char* value, const char* domain, const char* path, time_t expires);
    int add_entry(const char* name, const char* value, bool replace);
    // http response
    int set_method(const char* method);
    int set_host(const char* host);
    int set_accept(const char* accept);
    int set_accept_charset(const char* charset);
    int set_accept_encoding(const char* encoding);
    int set_accept_datetime(const char* datetime);
    int set_accept_language(const char* language);
    int set_authorization(const char* authorization);
    int set_cache_control(const char* cachecontrol);
    int set_connection(const char* connection);
    int set_content_md5(const char* md5);
    int set_content_type(const char* value);
    int set_data(const char* data);
    int set_dnt(const char* value);
    int set_expect(const char* expect);
    int set_etag(const char* etag);
    int set_forwarded(const char* forwarded);
    int set_use_agent(const char* agent);
    int set_keepalive(const char* value);
    int set_referer(const char* url);
    int set_range(const char* value);
    int set_upgrade_insecure_requests(const char* value);
    // http request
    int accept_gzip(bool on);
    int set_status(int status);
    int set_chunked(bool on);
    int set_cgi_mode(bool on);
    int set_transfer_gzip(bool on);
    int set_content_length(uint64 n);

private:
    std::string m_strmethod;
    std::map<std::string, std::string> m_maphttptable;
    std::string m_strresheader;
    std::string m_strreqheader;
};

#endif
